new Vue({
  el: "#app",
  data() {
    return {
      form: {
        Data: "dingtalk_application",
        Primary_Key: "",
        Primary_Key_Name: "Application_Name",
        isVague: true,
        page: 1, //页数
        limit: 10, //每页数据条数
      },
      total: 0,
      tableData: [], //表格数据
    };
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    onSerach() {
      //查询方法
      this.form.page = 1;
      this.getList(this.form);
    },
    Add() {
      window.location.href = "./Add.html";
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      //换页方法
      let _this = this;
      $.ajax({
        type: "POST",
        url: `${DomainName}/getTableInquiryAction?token=${$.cookie("token")}`,
        data,
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        success: function (Result) {
          if (Result.Status == "success") {
            _this.tableData = Result.tableData;
            console.log(_this.tableData);
            _this.total = parseInt(Result.limit);
          }
        },
        dataType: "json",
      });
    },
    Edit(App_ID) {
      sessionStorage.setItem("App_ID", App_ID);
      window.location.href = "./Edit.html?App_ID=" + App_ID;
    },
    onUserIds() {
      window.location.href = "./UserIDs.html";
    },
    Delete(row) {
      const _this = this;
      this.$confirm("警告！此操作将删除该服务, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $.ajax({
            url: DomainName + "/DeleteAction?token=" + $.cookie("token"),
            type: "POST",
            data: {
              TableName: "page_about_us_menu_info",
              Primary_Key: row.Page_AboutUs_Menu_SerialNumber,
              Primary_Key_Name: "Page_AboutUs_Menu_SerialNumber",
              Operation_Name: "删除钉钉应用",
            },
            success: function (res) {
              if (res.Status == "success") {
                _this.getList(_this.form);
                _this.$message({
                  type: "success",
                  message: "删除成功!",
                });
              }
            },
            // complete: function (XMLHttpRequest) {
            //     if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            //         window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            //     }
            // }
          });
        })
        .catch(() => {
          this.$message({
            type: "warning",
            message: "已取消操作",
          });
        });
    },
  },
});
